using System;
using System.Collections.Generic;
using DG.Tweening;
using Game.Component.Character;
using Game.Const;
using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class BaseItem : MonoBehaviour
	{
		public enum ZoomAnimType
		{
			Static = 0,
			ZoomIn = 1,
			ZoomOut = 2
		}

		public enum MoveAnimType
		{
			Static = 0,
			MoveToPoint = 1,
			MoveToLocalPoint = 2,
			MoveToTransform = 3,
			WalkToLocalPoint = 4,
			FreeFall = 5
		}

		public enum DragMoveAnimType
		{
			Static = 0,
			MoveUp = 1
		}

		public enum RotateAnimType
		{
			Static = 0,
			Rotation = 1
		}

		public enum AttachType
		{
			None = 0,
			Place = 1,
			PlacePoint = 2,
			LeftHandTake = 3,
			RightHandTake = 4,
			Sit = 5,
			LieLeft = 6,
			LieRight = 7,
			PutHead = 8,
			PutFace = 9,
			PutBody = 10,
			Wear = 11,
			StackUp = 12,
			Pack = 13,
			LieCenter = 14,
			PutLeftHand = 15,
			PutRightHand = 16,
			PutLeftLeg = 17,
			PutRightLeg = 18,
			LieLeftPlace = 19
		}

		public enum MoveToTransType
		{
			None = 0,
			Hand = 1
		}

		public enum ShaderType
		{
			Default = 0,
			Water = 1
		}

		public enum ChildDoThingType
		{
			Eat = 0
		}

		public const float COAT_HANGER_Y = -0.68f;

		public Transform model;

		public ItemArchiveData archiveData;

		public DepthSystem depthSystem;

		public BaseItem parentItem;

		public List<BaseItem> childItems = new List<BaseItem>();

		public AttachType attachType;

		public Transform frontMask;

		public Transform backMask;

		private bool isDestroy;

		protected SpriteRenderer[] sprites;

		protected AudioPlayer audioPlayer;

		protected float curModelOffsetX;

		private float targetModelOffsetX;

		protected float curModelOffsetY;

		private float originalModelOffsetX;

		private float originalModelOffsetY;

		private float targetModelOffsetY;

		private float modelMoveTime;

		protected MoveAnimType moveAnimType;

		protected Vector2 tempPoint;

		protected Vector2 moveEndPoint;

		protected Transform moveToTrans;

		protected MoveToTransType moveToTransType;

		protected bool needRebound;

		private float startMoveX;

		private float startMoveY;

		private float moveTime;

		private float accSpeed = 30f;

		private float accSpeedX;

		private float accSpeedY;

		private float moveYInitV;

		private float newX;

		private float newY;

		private int reboundNum;

		private bool isDown;

		private bool isArriveX;

		private bool isArriveY;

		public static int globalDragIndex;

		private int dragIndex;

		private Vector2 dragDifVal = Vector2.zero;

		private float originalDifValX;

		private float originalDifValY;

		private Vector2 dragPosition;

		protected Transform dragEfc;

		protected BoxCollider2D coll;

		protected bool isDrag;

		protected List<ColliderData> itemColls = new List<ColliderData>();

		protected List<ColliderData> itemCompColls = new List<ColliderData>();

		protected List<ColliderData> platformColls = new List<ColliderData>();

		protected List<Collider2D> storageBoxColls = new List<Collider2D>();

		private const float MAX_ZOOM_TIME = 0.14f;

		private ZoomAnimType zoomAnimType;

		protected float zoomTime;

		private float zoomSize;

		private const float DRAG_MOVE_UP_ANIM_TIME = 0.2f;

		private DragMoveAnimType dragMoveAnimType;

		private float dragMoveUpTime;

		private float dragMoveUpTimePercent;

		private Vector2 lastTouchPoint;

		private float moveSpeedX;

		protected bool isInSBArea;

		protected RotateAnimType rotateAnimType;

		protected float curAngle;

		protected float targetAngle;

		private bool forceStand;

		private float angleDif;

		private Vector2[] checkDirs = new Vector2[16]
		{
			new Vector2(0f, -2f),
			new Vector2(0f, 2f),
			new Vector2(-1f, -2f),
			new Vector2(1f, -2f),
			new Vector2(-1f, 2f),
			new Vector2(1f, 2f),
			new Vector2(-2f, -2f),
			new Vector2(2f, -2f),
			new Vector2(-2f, 2f),
			new Vector2(2f, 2f),
			new Vector2(-2f, -1f),
			new Vector2(2f, -1f),
			new Vector2(-2f, 1f),
			new Vector2(2f, 1f),
			new Vector2(-2f, 0f),
			new Vector2(2f, 0f)
		};

		protected List<Transform> platforms;

		protected bool inWater;

		private float floatValue;

		private float floatY;

		private float floatRange;

		public float waterHeight;

		private float waterY;

		private Transform waterLine;

		private bool isMuteInWater;

		private float touchDownTime;

		private uint putParentItemIndex;

		private int putParentItemAttachType;

		private int putParentItemDepthType;

		public ItemData itemData
		{
			get
			{
				return archiveData.itemData;
			}
		}

		public virtual void Init(ItemArchiveData data)
		{
			InitData(data);
			model = base.transform.Find("Model");
			if (model != null)
			{
				coll = model.GetComponent<BoxCollider2D>();
				originalModelOffsetX = model.localPosition.x;
				curModelOffsetX = originalModelOffsetX;
				targetModelOffsetX = curModelOffsetX;
				originalModelOffsetY = model.localPosition.y;
				curModelOffsetY = originalModelOffsetY;
				targetModelOffsetY = curModelOffsetY;
				model.gameObject.layer = 9;
				frontMask = model.Find("Front");
				frontMask.SetLocalZ(-1E-05f);
				backMask = model.Find("Back");
				backMask.SetLocalZ(1E-05f);
				InitPlatform();
			}
			depthSystem = new DepthSystem(this);
			SetCollilderTriggerEnabled(false);
			sprites = model.GetComponentsInChildren<SpriteRenderer>();
		}

		private void InitData(ItemArchiveData data)
		{
			archiveData = data;
			forceStand = data.forceStand;
			if (data.waterHeight != 0f || data.floatY != 0f)
			{
				waterHeight = data.waterHeight;
				floatY = data.floatY;
				floatValue = data.floatValue;
				floatRange = data.floatRange;
				waterY = data.waterY;
			}
		}

		protected virtual void LateUpdate()
		{
			if (archiveData != null)
			{
				LatedUpdateDrag();
				LatedUpdateModelMoveAnim();
				LateUpdateMoveAnim();
				LateUpdateZoomAnim();
				LateUpdateDragMoveAnim();
				LateUpdateRotateAnim();
				LatedUpdateWaterLine();
			}
		}

		protected virtual void LatedUpdateDrag()
		{
			if (isDrag && !isInSBArea)
			{
				if (parentItem == null)
				{
					SetPosition(Mathf.Lerp(base.transform.position.x, dragPosition.x + dragDifVal.x, Time.deltaTime * 20f), Mathf.Lerp(base.transform.position.y, dragPosition.y + dragDifVal.y, Time.deltaTime * 20f), -5f - (float)dragIndex * 0.001f);
				}
				OnMove();
			}
		}

		protected void LatedUpdateWaterLine()
		{
			if (waterLine != null)
			{
				if (base.transform.position.y <= waterHeight)
				{
					waterLine.gameObject.SetActive(true);
					waterLine.SetY(waterHeight);
				}
				else
				{
					waterLine.gameObject.SetActive(false);
				}
			}
		}

		protected void LatedUpdateModelMoveAnim()
		{
			if (curModelOffsetX == targetModelOffsetX && curModelOffsetY == targetModelOffsetY)
			{
				return;
			}
			if (curModelOffsetX > targetModelOffsetX)
			{
				curModelOffsetX -= Time.deltaTime * 4f;
				if (curModelOffsetX < targetModelOffsetX)
				{
					curModelOffsetX = targetModelOffsetX;
				}
			}
			else
			{
				curModelOffsetX += Time.deltaTime * 4f;
				if (curModelOffsetX > targetModelOffsetX)
				{
					curModelOffsetX = targetModelOffsetX;
				}
			}
			if (curModelOffsetY > targetModelOffsetY)
			{
				curModelOffsetY -= Time.deltaTime * 4f;
				if (curModelOffsetY < targetModelOffsetY)
				{
					curModelOffsetY = targetModelOffsetY;
				}
			}
			else
			{
				curModelOffsetY += Time.deltaTime * 4f;
				if (curModelOffsetY > targetModelOffsetY)
				{
					curModelOffsetY = targetModelOffsetY;
				}
			}
			model.SetLocalXY(curModelOffsetX, curModelOffsetY);
		}

		protected void LateUpdateMoveAnim()
		{
			if (moveAnimType == MoveAnimType.Static)
			{
				if (!ParentIsWater())
				{
					return;
				}
				if (moveYInitV > 1f)
				{
					moveYInitV -= Time.deltaTime / 2f;
					if (moveYInitV <= 1f)
					{
						moveYInitV = 1f;
					}
					floatValue += Time.deltaTime * moveYInitV;
					ResetFloatPosition();
				}
				else
				{
					floatValue += Time.deltaTime;
					ResetFloatPosition();
				}
				return;
			}
			if (moveAnimType == MoveAnimType.FreeFall)
			{
				moveTime += Time.deltaTime;
				if (isDown)
				{
					isArriveY = false;
					if (accSpeedX == 0f)
					{
						newX = base.transform.position.x;
						isArriveX = true;
					}
					else
					{
						isArriveX = false;
						newX = startMoveX + 0.5f * accSpeedX * moveTime * moveTime;
						if (accSpeedX < 0f)
						{
							if (newX <= moveEndPoint.x)
							{
								newX = moveEndPoint.x;
								isArriveX = true;
							}
						}
						else if (newX >= moveEndPoint.x)
						{
							newX = moveEndPoint.x;
							isArriveX = true;
						}
					}
					if (accSpeedY == 0f)
					{
						isArriveY = true;
						newY = base.transform.position.y;
					}
					else
					{
						isArriveY = false;
						newY = startMoveY + 0.5f * accSpeedY * moveTime * moveTime;
						if (accSpeedY < 0f)
						{
							if (newY <= moveEndPoint.y)
							{
								newY = moveEndPoint.y;
								isArriveY = true;
							}
						}
						else if (newY >= moveEndPoint.y)
						{
							newY = moveEndPoint.y;
							isArriveY = true;
						}
					}
					SetPosition(newX, newY);
					if (isArriveX && isArriveY)
					{
						if (reboundNum == 0)
						{
							if (inWater && parentItem != null && parentItem.itemData.scriptType == 40)
							{
								if (!isMuteInWater)
								{
									Singleton<AudioManager>.Instance.PlaySound("sound_fall_into_water");
									Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_water_fall", new Vector3(base.transform.position.x, archiveData.y, base.transform.position.z - 0.0004f), 3f);
								}
							}
							else
							{
								Singleton<AudioManager>.Instance.PlaySound("sound_put_down");
							}
						}
						if (!needRebound || reboundNum > 5)
						{
							moveYInitV = Mathf.Abs(accSpeedY * moveTime * 0.4f);
							moveAnimType = MoveAnimType.Static;
							FreeFallComplete();
						}
						else
						{
							isDown = false;
							if ((double)(startMoveY - newY) > 0.2)
							{
								accSpeedY = Mathf.Abs(accSpeedY);
								moveYInitV = accSpeedY * moveTime * 0.4f;
								moveTime = 0f;
								accSpeedX = 0f;
								reboundNum++;
							}
							else
							{
								moveAnimType = MoveAnimType.Static;
							}
						}
					}
				}
				else if (accSpeedY <= 0f || moveYInitV <= 0f)
				{
					SetPosition(moveEndPoint.x, moveEndPoint.y);
					moveAnimType = MoveAnimType.Static;
				}
				else
				{
					isArriveY = false;
					newY = moveEndPoint.y + moveYInitV * moveTime - 0.5f * accSpeedY * moveTime * moveTime;
					if (moveYInitV - moveTime * accSpeedY <= 0f || moveTime > 0.5f)
					{
						isArriveY = true;
					}
					SetPosition(moveEndPoint.x, newY);
					if (isArriveY)
					{
						startMoveY = newY;
						isDown = true;
						accSpeedY = 0f - accSpeedY;
						moveTime = 0f;
					}
				}
			}
			else if (moveAnimType == MoveAnimType.MoveToTransform)
			{
				moveTime += Time.deltaTime * 4f;
				if (moveToTrans == null)
				{
					moveAnimType = MoveAnimType.Static;
				}
				else
				{
					moveEndPoint = moveToTrans.position;
					if (moveToTransType == MoveToTransType.Hand)
					{
						moveEndPoint.x += itemData.holdX;
						moveEndPoint.y += itemData.holdY;
					}
					tempPoint = Vector2.Lerp(base.transform.position, moveEndPoint, moveTime);
					SetPosition(tempPoint.x, tempPoint.y);
					if (moveTime >= 1f)
					{
						moveToTrans = null;
						moveAnimType = MoveAnimType.Static;
					}
				}
			}
			else if (moveAnimType == MoveAnimType.WalkToLocalPoint)
			{
				if (base.transform.localPosition.y > moveEndPoint.y)
				{
					newY = base.transform.localPosition.y - 4f * Time.deltaTime;
					if (newY <= moveEndPoint.y)
					{
						newY = moveEndPoint.y;
					}
					else
					{
						newY = moveEndPoint.y;
					}
				}
				else if (base.transform.localPosition.x < moveEndPoint.x)
				{
					newY = base.transform.localPosition.x + 4f * Time.deltaTime;
					if (newY >= moveEndPoint.x)
					{
						newY = moveEndPoint.x;
					}
					else
					{
						newY = moveEndPoint.y;
					}
				}
				else
				{
					newY = moveEndPoint.x;
				}
				if (newY == moveEndPoint.x)
				{
					SetLocalPosition(moveEndPoint.x, moveEndPoint.y);
					moveAnimType = MoveAnimType.Static;
				}
				else
				{
					SetLocalPosition(newX, newY);
				}
			}
			else if (moveAnimType == MoveAnimType.MoveToLocalPoint)
			{
				moveTime += Time.deltaTime;
				tempPoint = Vector2.Lerp(base.transform.localPosition, moveEndPoint, moveTime);
				SetLocalPosition(tempPoint.x, tempPoint.y);
				if (moveTime >= 1f)
				{
					moveAnimType = MoveAnimType.Static;
				}
			}
			OnMove();
		}

		protected virtual void FreeFallComplete()
		{
		}

		protected void LateUpdateZoomAnim()
		{
			if (zoomAnimType == ZoomAnimType.Static)
			{
				return;
			}
			if (zoomAnimType == ZoomAnimType.ZoomIn)
			{
				zoomTime += Time.deltaTime;
				if (zoomTime >= 0.14f)
				{
					zoomTime = 0.14f;
					zoomAnimType = ZoomAnimType.Static;
				}
				zoomSize = itemData.scale * (1f + 0.12f * (zoomTime / 0.14f));
				SetLocalScale(new Vector3(zoomSize, zoomSize, 1f));
			}
			else if (zoomAnimType == ZoomAnimType.ZoomOut)
			{
				zoomTime -= Time.deltaTime;
				if (zoomTime <= 0f)
				{
					zoomTime = 0f;
					zoomAnimType = ZoomAnimType.Static;
				}
				zoomSize = itemData.scale * (1f + 0.12f * (zoomTime / 0.14f));
				SetLocalScale(new Vector3(zoomSize, zoomSize, 1f));
			}
		}

		protected void LateUpdateDragMoveAnim()
		{
			if (dragMoveAnimType == DragMoveAnimType.MoveUp)
			{
				dragMoveUpTime += Time.deltaTime;
				if (dragMoveUpTime >= 0.2f)
				{
					dragMoveUpTime = 0.2f;
					dragMoveAnimType = DragMoveAnimType.Static;
				}
				dragMoveUpTimePercent = dragMoveUpTime / 0.2f;
				originalDifValX = Mathf.Lerp(originalDifValX, 0f, dragMoveUpTimePercent);
				dragDifVal.x = originalDifValX + itemData.dragX * dragMoveUpTimePercent;
				dragDifVal.y = originalDifValY + itemData.dragY * dragMoveUpTimePercent;
			}
		}

		protected void LateUpdateRotateAnim()
		{
			if (rotateAnimType != 0 && rotateAnimType == RotateAnimType.Rotation)
			{
				angleDif = Mathf.Abs(curAngle - targetAngle);
				if (((!(angleDif > 180f)) ? angleDif : Mathf.Abs(angleDif - 360f)) < 0.4f)
				{
					curAngle = targetAngle;
					rotateAnimType = RotateAnimType.Static;
				}
				else
				{
					curAngle = Mathf.LerpAngle(curAngle, targetAngle, Time.deltaTime * 10f);
				}
				SetLocalRotation(new Vector3(0f, 0f, curAngle));
			}
		}

		public Vector3 GetLocalScale()
		{
			return base.transform.localScale;
		}

		public void SetLocalScale(Vector3 val)
		{
			if (archiveData.dirX >= 0)
			{
				CheckParentScale(true, val);
			}
			else
			{
				CheckParentScale(false, val);
			}
		}

		private void CheckParentScale(bool isFront, Vector3 val)
		{
			if (isFront)
			{
				if (base.transform.parent != null)
				{
					if (attachType == AttachType.PutLeftHand || attachType == AttachType.PutRightHand)
					{
						base.transform.localScale = new Vector3(Mathf.Abs(val.x), val.y, val.z);
					}
					else if (base.transform.parent.lossyScale.x >= 0f)
					{
						base.transform.localScale = new Vector3(Mathf.Abs(val.x), val.y, val.z);
					}
					else
					{
						base.transform.localScale = new Vector3(0f - Mathf.Abs(val.x), val.y, val.z);
					}
				}
				else
				{
					base.transform.localScale = new Vector3(Mathf.Abs(val.x) * (float)((base.transform.localScale.x >= 0f) ? 1 : (-1)), val.y, val.z);
				}
			}
			else if (base.transform.parent != null)
			{
				if (attachType == AttachType.PutLeftHand || attachType == AttachType.PutRightHand)
				{
					base.transform.localScale = new Vector3(Mathf.Abs(val.x), val.y, val.z);
				}
				else if (base.transform.parent.lossyScale.x < 0f)
				{
					base.transform.localScale = new Vector3(Mathf.Abs(val.x), val.y, val.z);
				}
				else
				{
					base.transform.localScale = new Vector3(0f - Mathf.Abs(val.x), val.y, val.z);
				}
			}
			else
			{
				base.transform.localScale = new Vector3(Mathf.Abs(val.x) * (float)((!(base.transform.localScale.x >= 0f)) ? 1 : (-1)), val.y, val.z);
			}
		}

		public void SetAlpha(float alpha)
		{
			if (model != null)
			{
				model.GetComponent<SpriteRenderer>().SetSpriteAlpha(alpha);
			}
		}

		public virtual void SetVisible(bool val)
		{
			if (base.transform != null)
			{
				base.transform.gameObject.SetActive(val);
			}
		}

		public void ResetLocalScale()
		{
			SetLocalScale(GetLocalScale());
		}

		public virtual void FlipHorizontal(bool turnToFront)
		{
			if (turnToFront)
			{
				if (archiveData.dirX < 0)
				{
					archiveData.dirX = 1;
					SetLocalScale(GetLocalScale());
					ResetChildScale();
				}
			}
			else if (archiveData.dirX >= 0)
			{
				archiveData.dirX = -1;
				SetLocalScale(GetLocalScale());
				ResetChildScale();
			}
		}

		private void ResetChildScale()
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				childItems[i].SetLocalScale(childItems[i].GetLocalScale());
			}
		}

		public void SetParent(Transform parent)
		{
			base.transform.SetParent(parent);
		}

		public void SetPosition(float x, float y)
		{
			SetPosition(x, y, base.transform.position.z);
		}

		public void SetPosition(float x, float y, float z)
		{
			base.transform.position = new Vector3(x, y, z);
		}

		public virtual bool CanSit()
		{
			if (itemData.canSit)
			{
				if (itemData.sitType == 2)
				{
					return true;
				}
				for (int i = 0; i < childItems.Count; i++)
				{
					if (childItems[i].attachType == AttachType.Sit)
					{
						return false;
					}
				}
				return true;
			}
			return false;
		}

		public virtual bool CanDestroyItem(BaseItem item)
		{
			return false;
		}

		public virtual bool CanTouch()
		{
			if (itemData.canDrag || itemData.canTouch)
			{
				return true;
			}
			return false;
		}

		public virtual bool CanLie()
		{
			if (itemData.lieType != 0)
			{
				for (int i = 0; i < childItems.Count; i++)
				{
					if (childItems[i].attachType == AttachType.LieLeft || childItems[i].attachType == AttachType.LieRight || childItems[i].attachType == AttachType.LieCenter)
					{
						return false;
					}
				}
				return true;
			}
			return false;
		}

		public bool CanPlacePoint()
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i].attachType == AttachType.PlacePoint)
				{
					return false;
				}
			}
			return true;
		}

		public virtual bool CanPlaceInHead()
		{
			return itemData.canPutHead;
		}

		public virtual bool CanPutHead()
		{
			return false;
		}

		public virtual bool CanPlaceInFace()
		{
			return itemData.canPutFace;
		}

		public virtual bool CanPutFace()
		{
			return false;
		}

		public virtual bool CanPlaceInBody()
		{
			return itemData.canPutBody;
		}

		public virtual bool CanPutBody()
		{
			return false;
		}

		public virtual bool CanPlaceInHand()
		{
			return itemData.canPutHand;
		}

		public virtual bool CanPutHand()
		{
			return false;
		}

		protected virtual void OnTriggerEnter2D(Collider2D collision)
		{
			if (!isDrag)
			{
				return;
			}
			if (collision.gameObject.layer == 9)
			{
				BaseItem component = collision.transform.parent.GetComponent<BaseItem>();
				if (component != null && !ContainerItemColl(component, null, null, itemColls))
				{
					ColliderData colliderData = new ColliderData(collision, component);
					itemColls.Add(colliderData);
					OnItemTriggerEnter(colliderData);
				}
			}
			else if (collision.gameObject.layer == 11)
			{
				BaseItem component2 = collision.transform.parent.parent.GetComponent<BaseItem>();
				if (component2 != null && !ContainerItemColl(null, null, collision, platformColls))
				{
					ColliderData colliderData2 = new ColliderData(collision, component2);
					platformColls.Add(colliderData2);
					OnPlatformCheckAreaTriggerEnter(colliderData2);
				}
			}
			else if (collision.gameObject.layer == 12)
			{
				ItemComponentTrigger component3 = collision.gameObject.GetComponent<ItemComponentTrigger>();
				if (component3 != null && !ContainerItemColl(null, component3, null, itemCompColls))
				{
					ColliderData colliderData3 = new ColliderData(collision, component3);
					itemCompColls.Add(colliderData3);
					if (component3.OnEnterCollision != null)
					{
						component3.OnEnterCollision(this, component3);
					}
					OnItemCompTriggerEnter(colliderData3);
				}
			}
			else if (itemData.scriptType == 1 && collision.gameObject.layer == 13 && !storageBoxColls.Contains(collision))
			{
				storageBoxColls.Add(collision);
			}
		}

		protected virtual void OnItemTriggerEnter(ColliderData collData)
		{
		}

		protected virtual void OnPlatformCheckAreaTriggerEnter(ColliderData collData)
		{
		}

		protected virtual void OnItemCompTriggerEnter(ColliderData collData)
		{
		}

		private bool ContainerItemColl(BaseItem item, ItemComponentTrigger trigger, Collider2D coll, List<ColliderData> list)
		{
			for (int i = 0; i < list.Count; i++)
			{
				if (item != null)
				{
					if (list[i].item == item)
					{
						return true;
					}
				}
				else if (trigger != null)
				{
					if (list[i].trigger == trigger)
					{
						return true;
					}
				}
				else if (coll != null && list[i].coll == coll)
				{
					return true;
				}
			}
			return false;
		}

		protected virtual void OnTriggerExit2D(Collider2D collision)
		{
			if (!isDrag)
			{
				return;
			}
			if (collision.gameObject.layer == 9)
			{
				ColliderData colliderData = RemoveColl(itemColls, collision);
				if (colliderData != null)
				{
					OnItemTriggerExit(colliderData);
				}
			}
			else if (collision.gameObject.layer == 11)
			{
				ColliderData colliderData2 = RemoveColl(platformColls, collision);
				if (colliderData2 != null)
				{
					OnPlatformCheckAreaTriggerExit(colliderData2);
				}
			}
			else if (collision.gameObject.layer == 12)
			{
				ColliderData colliderData3 = RemoveColl(itemCompColls, collision);
				if (colliderData3 != null)
				{
					if (colliderData3.trigger.OnExitCollision != null)
					{
						colliderData3.trigger.OnExitCollision(this, colliderData3.trigger);
					}
					OnItemCompTriggerExit(colliderData3);
				}
			}
			else if (collision.gameObject.layer == 13)
			{
				storageBoxColls.Remove(collision);
			}
		}

		protected virtual void OnItemTriggerExit(ColliderData collData)
		{
		}

		protected virtual void OnPlatformCheckAreaTriggerExit(ColliderData collData)
		{
		}

		protected virtual void OnItemCompTriggerExit(ColliderData collData)
		{
		}

		private ColliderData RemoveColl(List<ColliderData> list, Collider2D coll)
		{
			for (int i = 0; i < list.Count; i++)
			{
				ColliderData colliderData = list[i];
				if (colliderData.coll == coll)
				{
					list.RemoveAt(i);
					return colliderData;
				}
			}
			return null;
		}

		private void ClearColls()
		{
			itemColls.Clear();
			platformColls.Clear();
			storageBoxColls.Clear();
			for (int i = 0; i < itemCompColls.Count; i++)
			{
				if (itemCompColls[i].trigger != null && itemCompColls[i].trigger.OnExitCollision != null)
				{
					itemCompColls[i].trigger.OnExitCollision(this, itemCompColls[i].trigger);
				}
			}
			itemCompColls.Clear();
		}

		private void SetCollilderTriggerEnabled(bool val)
		{
			if (coll != null)
			{
				coll.isTrigger = val;
			}
		}

		public virtual void TouchDown(TouchEventData touchEventData)
		{
			touchDownTime = Time.realtimeSinceStartup;
			if (archiveData == null)
			{
				return;
			}
			ClearColls();
			moveAnimType = MoveAnimType.Static;
			PlayClickSound();
			if (itemData.canDrag)
			{
				isDrag = true;
				if (parentItem != null)
				{
					parentItem.ReleaseAttachItem(this);
				}
				ResetComponentState();
				InWater(false, 0f);
				forceStand = false;
				isInSBArea = touchEventData.inSBArea;
				dragIndex = GenarateDragIndex();
				SetComponentTriggerEnabled(true);
				SetCollilderTriggerEnabled(true);
				lastTouchPoint = touchEventData.curPos;
				dragDifVal = (Vector2)base.transform.position - touchEventData.curPos;
				originalDifValX = dragDifVal.x;
				originalDifValY = dragDifVal.y;
				dragPosition = touchEventData.curPos;
				ZoomIn();
				MoveUp();
				PlayDragRotateAnim(false);
				PlayDragEffect();
				PlayDragSound();
				Singleton<AudioManager>.Instance.PlaySound("sound_drag");
			}
		}

		protected virtual void PlayDragEffect(float z = -0.0004f)
		{
			if (string.IsNullOrEmpty(itemData.dragEfc))
			{
				return;
			}
			if (dragEfc == null)
			{
				Transform transform = model.Find("DragEfc");
				if (transform != null)
				{
					transform.SetLocalZ(z);
					dragEfc = Singleton<GamePoolManager>.Instance.Spawn(PathConst.EFFECT + itemData.dragEfc);
					if (dragEfc != null)
					{
						dragEfc.SetParent(transform);
						dragEfc.localPosition = Vector3.zero;
						dragEfc.localScale = Vector3.one;
						dragEfc.localEulerAngles = Vector3.zero;
					}
				}
			}
			SetEffectLoop(dragEfc, true);
		}

		protected void StopDragEffect()
		{
			SetEffectLoop(dragEfc, false);
		}

		public virtual void PlayClickSound()
		{
			if (itemData.clickSound != null)
			{
				Singleton<AudioManager>.Instance.PlaySound(itemData.clickSound[UnityEngine.Random.Range(0, itemData.clickSound.Length)]);
			}
		}

		public virtual void PlayQuicklyClickSound()
		{
			if (itemData.quicklyClickSound != null)
			{
				Singleton<AudioManager>.Instance.PlaySound(itemData.quicklyClickSound[UnityEngine.Random.Range(0, itemData.quicklyClickSound.Length)]);
			}
		}

		protected void PlayAudio(string name, bool isLoop = true)
		{
			if (!string.IsNullOrEmpty(name))
			{
				Singleton<AudioManager>.Instance.PlayAudio(name, isLoop, GetAudioPlayer());
			}
		}

		protected virtual void PlayDragSound()
		{
			if (itemData.dragSound != null)
			{
				Singleton<AudioManager>.Instance.PlayAudio(itemData.dragSound[UnityEngine.Random.Range(0, itemData.dragSound.Length)], true, GetAudioPlayer());
			}
		}

		protected virtual void StopDragSound()
		{
			if (itemData.dragSound != null)
			{
				RemoveAudioPlayer();
			}
		}

		protected void SetEffectLoop(Transform efc, bool val)
		{
			if (!(efc != null))
			{
				return;
			}
			ParticleSystem[] componentsInChildren = efc.GetComponentsInChildren<ParticleSystem>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				ParticleSystem.MainModule main = componentsInChildren[i].main;
				main.loop = val;
				if (val)
				{
					componentsInChildren[i].Play();
				}
			}
		}

		public void InWater(bool val, float newWaterHeight)
		{
			if (inWater == val)
			{
				return;
			}
			inWater = val;
			waterHeight = newWaterHeight;
			if (inWater)
			{
				ChangeShader(ShaderType.Water);
				SetShaderWaterHeight(waterHeight);
				if (ParentIsWater())
				{
					AddWaterLine();
				}
				archiveData.y = waterY;
			}
			else
			{
				ChangeShader(ShaderType.Default);
				RemoveWaterLine();
				floatValue = 0f;
				floatY = 0f;
				floatRange = 0f;
				waterHeight = 0f;
				waterY = 0f;
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				childItems[i].InWater(val, waterHeight);
			}
		}

		public bool ParentIsWater()
		{
			if (inWater && parentItem != null && parentItem.itemData.scriptType == 40)
			{
				return true;
			}
			return false;
		}

		public void CheckCanPutOtherScene()
		{
			if (itemData.dontPutOtherScene && parentItem != null && parentItem.itemData.scriptType == 1)
			{
				putParentItemIndex = parentItem.archiveData.index;
				putParentItemAttachType = (int)attachType;
				putParentItemDepthType = (int)depthSystem.depthType;
				parentItem.ReleaseAttachItem(this);
			}
		}

		public bool ParentIsCharacter()
		{
			if (parentItem != null)
			{
				if (parentItem.itemData.scriptType == 1)
				{
					return true;
				}
				return parentItem.ParentIsCharacter();
			}
			return false;
		}

		private void ChangeShader(ShaderType shaderType)
		{
			if (sprites == null)
			{
				return;
			}
			for (int i = 0; i < sprites.Length; i++)
			{
				string text = sprites[i].material.shader.name;
				switch (shaderType)
				{
				case ShaderType.Default:
					if (text.Equals("Sprites/DiffuseWater"))
					{
						sprites[i].material.shader = Singleton<AssetBundleManager>.Instance.GetShader("Sprites/Diffuse");
					}
					else if (text.Equals("Sprites/DiffuseWaterFill"))
					{
						sprites[i].material.shader = Singleton<AssetBundleManager>.Instance.GetShader("Sprites/DiffuseFill");
					}
					break;
				case ShaderType.Water:
					if (text.Equals("Sprites/Diffuse"))
					{
						sprites[i].material.shader = Singleton<AssetBundleManager>.Instance.GetShader("Sprites/DiffuseWater");
					}
					else if (text.Equals("Sprites/DiffuseFill"))
					{
						sprites[i].material.shader = Singleton<AssetBundleManager>.Instance.GetShader("Sprites/DiffuseWaterFill");
					}
					break;
				}
			}
		}

		private void SetShaderWaterHeight(float val)
		{
			for (int i = 0; i < sprites.Length; i++)
			{
				sprites[i].material.SetFloat("_WaterHeight", val);
			}
		}

		private void AddWaterLine()
		{
			if (waterLine == null && (itemData.floatType == 0 || itemData.floatType == 2))
			{
				waterLine = Singleton<GamePoolManager>.Instance.Spawn(PathConst.EFFECT + "efc_water_wave");
				waterLine.position = new Vector3(archiveData.x, waterHeight);
				waterLine.localScale = new Vector3(CalculateWaterLineScale(), 1f, 1f);
			}
		}

		private float CalculateWaterLineScale()
		{
			if (coll != null)
			{
				if (CalculateAngle() == 0)
				{
					float num = coll.transform.lossyScale.x * (itemData.scale / GetLocalScale().x);
					return coll.size.x * num * 1.44f;
				}
				float num2 = coll.transform.lossyScale.y * (itemData.scale / GetLocalScale().y);
				return coll.size.y * num2 * 1.44f;
			}
			return 0f;
		}

		public bool IsStatic()
		{
			return moveAnimType == MoveAnimType.Static;
		}

		private void RemoveWaterLine()
		{
			if (waterLine != null)
			{
				Singleton<GamePoolManager>.Instance.Despawn(waterLine);
				waterLine = null;
			}
		}

		protected virtual void ResetComponentState()
		{
		}

		protected virtual void SetComponentTriggerEnabled(bool val)
		{
		}

		public virtual void PlayDragRotateAnim(bool isBack)
		{
			int num = 0;
			num = ((!isBack) ? itemData.dragAngle : CalculateAngle());
			RotateToAngle(num);
			if (coll != null)
			{
				if (num > 60)
				{
					CalculateModelOffset(true);
					return;
				}
				if (num < -60)
				{
					CalculateModelOffset(false);
					return;
				}
				targetModelOffsetX = originalModelOffsetX;
				targetModelOffsetY = originalModelOffsetY;
			}
		}

		public void RotateToAngle(float angle)
		{
			targetAngle = angle;
			curAngle = GetLocalRotation().eulerAngles.z;
			if (curAngle != targetAngle)
			{
				rotateAnimType = RotateAnimType.Rotation;
			}
			else
			{
				rotateAnimType = RotateAnimType.Static;
			}
		}

		public virtual void ResetState()
		{
			if (archiveData.putParentItemIndex != 0)
			{
				BaseItem item = Singleton<Scene>.Instance.GetItem(archiveData.putParentItemIndex);
				if (item != null && item.archiveData.layer != 9)
				{
					item.AttachItem(this, (DepthType)archiveData.putParentItemDepthType, (AttachType)archiveData.putParentItemAttachType, true);
				}
				archiveData.putParentItemIndex = 0u;
				archiveData.putParentItemAttachType = 0;
				archiveData.putParentItemDepthType = 0;
			}
			ResetAngle();
			if (archiveData.resetPlace)
			{
				base.transform.SetLocalXY(archiveData.placeX, archiveData.placeY);
			}
		}

		public void ResetAngle()
		{
			float num = CalculateAngle();
			SetLocalRotation(new Vector3(0f, 0f, num));
			if (num > 60f)
			{
				CalculateModelOffset(true);
			}
			else
			{
				if (!(num < -60f))
				{
					return;
				}
				CalculateModelOffset(false);
			}
			curModelOffsetX = targetModelOffsetX;
			model.SetLocalX(curModelOffsetX);
		}

		private void ResetFloatPosition()
		{
			SetPosition(base.transform.position.x, floatY + floatRange * Mathf.Sin(floatValue));
		}

		protected virtual int CalculateAngle()
		{
			if (forceStand)
			{
				return 0;
			}
			if (parentItem != null)
			{
				if (attachType == AttachType.LeftHandTake || attachType == AttachType.RightHandTake)
				{
					return itemData.holdAngle;
				}
				if (attachType == AttachType.PutFace)
				{
					return itemData.putFaceAngle;
				}
				if (attachType == AttachType.PutHead)
				{
					return itemData.putHeadAngle;
				}
				if (parentItem.itemData.canPlaceTypes != null && itemData.parentAngleTyes != null)
				{
					for (int i = 0; i < itemData.parentAngleTyes.Length; i++)
					{
						int num = itemData.parentAngleTyes[i];
						for (int j = 0; j < parentItem.itemData.canPlaceTypes.Length; j++)
						{
							if (parentItem.itemData.canPlaceTypes[j] == num)
							{
								return itemData.parentAngles[i];
							}
						}
					}
				}
			}
			return itemData.normalAngle;
		}

		private void MoveUp()
		{
			if (itemData.dragX > 0f || itemData.dragY > 0f || originalDifValX != 0f)
			{
				dragMoveUpTime = 0f;
				dragMoveAnimType = DragMoveAnimType.MoveUp;
			}
		}

		private void ZoomIn()
		{
			if (zoomAnimType != ZoomAnimType.ZoomIn)
			{
				zoomAnimType = ZoomAnimType.ZoomIn;
			}
		}

		private void ZoomOut()
		{
			if (zoomAnimType != ZoomAnimType.ZoomOut)
			{
				zoomAnimType = ZoomAnimType.ZoomOut;
			}
		}

		public virtual void TouchMove(TouchEventData touchEventData)
		{
			isInSBArea = touchEventData.inSBArea;
			if (touchEventData.inSBArea || !isDrag)
			{
				return;
			}
			if (itemData.canFlip)
			{
				moveSpeedX = lastTouchPoint.x - touchEventData.curPos.x;
				if (moveSpeedX > 0.2f)
				{
					FlipHorizontal(false);
				}
				else if (moveSpeedX < -0.2f)
				{
					FlipHorizontal(true);
				}
				lastTouchPoint = touchEventData.curPos;
			}
			dragPosition = touchEventData.curPos;
		}

		public virtual void TriggerTouchUpEvent()
		{
		}

		public virtual void TouchUp(TouchEventData touchEventData)
		{
			if (Time.realtimeSinceStartup - touchDownTime < 0.2f)
			{
				QuicklyTouch(touchEventData);
			}
			if (isDrag)
			{
				isDrag = false;
				ZoomOut();
				if (!touchEventData.inSBArea)
				{
					SortCollList(itemColls);
					SortCollList(itemCompColls);
					SortCollList(platformColls);
					CheckColls();
				}
				if (!isDestroy)
				{
					PlayDragRotateAnim(true);
				}
				SetComponentTriggerEnabled(false);
				SetCollilderTriggerEnabled(false);
				depthSystem.SortBaseNode();
				StopDragEffect();
				StopDragSound();
			}
			ClearColls();
		}

		public void DropDown(Vector3 position, bool needCheckPlatform = false)
		{
			if (needCheckPlatform)
			{
				RaycastHit2D[] array = Physics2D.RaycastAll(position, Vector2.zero, 15f, 2048);
				List<ColliderData> list = new List<ColliderData>();
				for (int i = 0; i < array.Length; i++)
				{
					BaseItem component = array[i].collider.transform.parent.parent.GetComponent<BaseItem>();
					if (component != null && !ContainerItemColl(null, null, array[i].collider, list))
					{
						ColliderData item = new ColliderData(array[i].collider, component);
						list.Add(item);
					}
				}
				SortCollList(list);
				if (CheckPlatforms(list))
				{
					depthSystem.baseNode.SortSelf(true);
					PlayDragRotateAnim(true);
					return;
				}
			}
			PlacePointData placePointData = CheckPlatform(position, 8, null, false, true, itemData.normalAngle);
			if (placePointData.result)
			{
				FreeFall(base.transform.position, placePointData.position);
				Singleton<Scene>.Instance.AttachItemToLayer(this, 0);
				depthSystem.baseNode.SortSelf(true);
				PlayDragRotateAnim(true);
			}
		}

		public virtual void QuicklyTouch(TouchEventData touchEventData)
		{
			PlayQuicklyClickSound();
		}

		public virtual void TouchUpOnSameItem(TouchEventData touchEventData)
		{
		}

		public void SetArchiveDataPosition(Vector2 point)
		{
			archiveData.x = point.x;
			archiveData.y = point.y;
		}

		protected void UpdateNodes()
		{
		}

		protected virtual void CheckColls()
		{
			if (ScriptCheckCollsStart())
			{
				return;
			}
			if (CanPlaceInHead())
			{
				for (int i = 0; i < itemCompColls.Count; i++)
				{
					if (itemCompColls[i].trigger != null && itemCompColls[i].trigger.type == ItemComponentTrigger.Type.Head && itemCompColls[i].trigger.OnAttachItem != null && itemCompColls[i].trigger.owner.CanPutHead())
					{
						moveToTrans = itemCompColls[i].trigger.OnAttachItem(this, itemCompColls[i].trigger);
						if (moveToTrans != null)
						{
							MoveToLocalPosition(new Vector2(itemData.putHeadX, itemData.putHeadY));
							return;
						}
					}
				}
			}
			if (CanPlaceInFace())
			{
				for (int j = 0; j < itemCompColls.Count; j++)
				{
					if (itemCompColls[j].trigger != null && itemCompColls[j].trigger.type == ItemComponentTrigger.Type.Face && itemCompColls[j].trigger.OnAttachItem != null && itemCompColls[j].trigger.owner.CanPutFace())
					{
						moveToTrans = itemCompColls[j].trigger.OnAttachItem(this, itemCompColls[j].trigger);
						if (moveToTrans != null)
						{
							MoveToLocalPosition(new Vector2(itemData.putFaceX, itemData.putFaceY));
							return;
						}
					}
				}
			}
			if (CanPlaceInBody())
			{
				for (int k = 0; k < itemCompColls.Count; k++)
				{
					if (itemCompColls[k].trigger != null && itemCompColls[k].trigger.type == ItemComponentTrigger.Type.Body && itemCompColls[k].trigger.OnAttachItem != null && itemCompColls[k].trigger.owner.CanPutBody())
					{
						moveToTrans = itemCompColls[k].trigger.OnAttachItem(this, itemCompColls[k].trigger);
						if (moveToTrans != null)
						{
							MoveToLocalPosition(new Vector2(itemData.putBodyX, itemData.putBodyY));
							return;
						}
					}
				}
			}
			if (CanPlaceInHand())
			{
				for (int l = 0; l < itemCompColls.Count; l++)
				{
					if (itemCompColls[l].trigger != null && (itemCompColls[l].trigger.type == ItemComponentTrigger.Type.LeftHand || itemCompColls[l].trigger.type == ItemComponentTrigger.Type.RightHand) && itemCompColls[l].trigger.OnAttachItem != null && itemCompColls[l].trigger.owner.CanPutHand())
					{
						moveToTrans = itemCompColls[l].trigger.OnAttachItem(this, itemCompColls[l].trigger);
						if (moveToTrans != null)
						{
							MoveToLocalPosition(new Vector2(itemData.putHandX, itemData.putHandY));
							return;
						}
					}
				}
			}
			if (itemData.canHold)
			{
				for (int m = 0; m < itemCompColls.Count; m++)
				{
					if (itemCompColls[m].trigger != null && !ContainsChild(itemCompColls[m].trigger.owner) && (itemCompColls[m].trigger.type == ItemComponentTrigger.Type.LeftHand || itemCompColls[m].trigger.type == ItemComponentTrigger.Type.RightHand) && itemCompColls[m].trigger.OnAttachItem != null)
					{
						moveToTrans = itemCompColls[m].trigger.OnAttachItem(this, itemCompColls[m].trigger);
						if (moveToTrans != null)
						{
							MoveToLocalPosition(new Vector2(itemData.holdX, itemData.holdY));
							return;
						}
					}
				}
			}
			if (CanEat())
			{
				for (int n = 0; n < itemCompColls.Count; n++)
				{
					if (itemCompColls[n].trigger.type == ItemComponentTrigger.Type.Mouth && typeof(CharacterItem).IsAssignableFrom(itemCompColls[n].trigger.owner.GetType()))
					{
						CharacterItem characterItem = (CharacterItem)itemCompColls[n].trigger.owner;
						if (characterItem.CanEatThings())
						{
							characterItem.EatThings(this);
							GlobalEventSystem.Fire(new BaseEvent("game.remove_item", archiveData.index));
							return;
						}
					}
				}
			}
			if (itemData.canDestroy && itemData.type != 1)
			{
				for (int num = 0; num < itemColls.Count; num++)
				{
					BaseItem item = itemColls[num].item;
					if (item.CanDestroyItem(this))
					{
						isDestroy = true;
						SetColliderEnabled(true);
						item.AttachItem(this, DepthType.Front, AttachType.Place, false);
						base.transform.DOScale(new Vector3(0.2f, 0.2f, 1f), 0.35f);
						base.transform.DOJump(item.GetDestroyPoint().position + new Vector3(0f, 0f, -0.001f), 0.6f, 1, 0.35f).onComplete = delegate
						{
							item.PlayDestroyShakeAnim();
							GlobalEventSystem.Fire(new BaseEvent("game.remove_item", archiveData.index));
						};
						return;
					}
				}
			}
			if ((CanPlacePlatform() && CheckPlatforms(platformColls)) || CheckWater(platformColls))
			{
				return;
			}
			if (itemData.composeData != null && childItems.Count <= 0)
			{
				for (int num2 = 0; num2 < itemColls.Count; num2++)
				{
					BaseItem item2 = itemColls[num2].item;
					if (!(item2.parentItem == null) || item2.childItems.Count > 0)
					{
						continue;
					}
					for (int num3 = 0; num3 < itemData.composeData.Count; num3++)
					{
						if ((itemData.composeData[num3].id1.Equals(itemData.id) && itemData.composeData[num3].id2.Equals(item2.itemData.id)) || (itemData.composeData[num3].id2.Equals(itemData.id) && itemData.composeData[num3].id1.Equals(item2.itemData.id)))
						{
							BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(itemData.composeData[num3].id3, item2.transform.position, 0);
							if (baseItem != null)
							{
								GlobalEventSystem.Fire(new BaseEvent("game.remove_item", archiveData.index));
								GlobalEventSystem.Fire(new BaseEvent("game.remove_item", item2.archiveData.index));
								Singleton<AudioManager>.Instance.PlaySound("sound_explode");
								Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", baseItem.transform.position + new Vector3(0f, 0.4f, -0.0004f), 1f);
								Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", baseItem.transform.position + new Vector3(0f, 0.4f, -0.0004f), 3f);
							}
							return;
						}
					}
				}
			}
			if (!ScriptCheckCollsEnd())
			{
				PlacePointData placePointData = CheckPlatform(base.transform.position, 8, null, false, true, itemData.normalAngle);
				if (placePointData.result)
				{
					FreeFall(base.transform.position, placePointData.position);
					Singleton<Scene>.Instance.AttachItemToLayer(this, 0);
				}
				else
				{
					Debug.LogError("物品未找到可以放置的地表" + itemData.id);
					SetArchiveDataPosition(base.transform.position);
					Singleton<Scene>.Instance.AttachItemToLayer(this, 0);
				}
			}
		}

		private bool CheckPlatforms(List<ColliderData> platforms)
		{
			for (int i = 0; i < platforms.Count; i++)
			{
				ColliderData colliderData = platforms[i];
				if (colliderData == null || !(colliderData.item != null))
				{
					continue;
				}
				BaseItem item = colliderData.item;
				if (!item.CanAttatchItem() || !CanPlaceOnPlatform(item))
				{
					continue;
				}
				if (item.itemData.placeAttachType == 1)
				{
					if (item.CanPlacePoint() && PlaceOnPlatform(item, colliderData.coll.transform, true, false) && item.AttachItem(this, (DepthType)item.itemData.placeSortType, AttachType.PlacePoint, false))
					{
						if (item.itemData.type == 3)
						{
							FreeFall(base.transform.position, item.GetPlacePoint().position + new Vector3(0f, -0.68f, 0f));
						}
						else
						{
							FreeFall(base.transform.position, item.GetPlacePoint().position);
						}
						return true;
					}
				}
				else if (PlaceOnPlatform(item, colliderData.coll.transform, false, item.itemData.checkDirType == 0))
				{
					return true;
				}
			}
			return false;
		}

		protected virtual bool CanPlaceOnPlatform(BaseItem item)
		{
			if (item.itemData.scriptType == 40 || ContainsChild(item))
			{
				return false;
			}
			if (item.itemData.placeAmount > 0 && item.childItems.Count >= item.itemData.placeAmount)
			{
				return false;
			}
			return true;
		}

		private bool CheckWater(List<ColliderData> platforms)
		{
			for (int i = 0; i < platforms.Count; i++)
			{
				ColliderData colliderData = platforms[i];
				if (colliderData == null || !(colliderData.item != null))
				{
					continue;
				}
				BaseItem item = colliderData.item;
				if (item.itemData.scriptType == 40 && !(((WaterItem)item).GetCheckPlaceY() > base.transform.position.y))
				{
					float placeAngle = CalculatePlaceAngle(item);
					PlacePointData placePointData = CheckPlatform(base.transform.position, 10, colliderData.coll.transform, false, true, placeAngle);
					if (placePointData.result)
					{
						CalculateFloatData(placePointData.position, placeAngle, false);
						SetArchiveDataPosition(placePointData.position);
						waterHeight = archiveData.y;
						waterY = archiveData.y;
						item.AttachItem(this, (DepthType)item.itemData.placeSortType, AttachType.Place, false);
						return true;
					}
				}
			}
			return false;
		}

		public virtual bool CanPlacePlatform()
		{
			return itemData.placeType != 0;
		}

		public virtual bool CanAttatchItem()
		{
			return true;
		}

		public virtual bool CanEat()
		{
			return itemData.canEat;
		}

		private void CalculateFloatData(Vector2 position, float placeAngle, bool isMute)
		{
			if (placeAngle == 0f)
			{
				float num = coll.transform.lossyScale.y * (itemData.scale / GetLocalScale().y);
				float num2 = coll.size.y * num;
				floatRange = num2 * 0.1f;
				if (itemData.floatType == 1)
				{
					floatY = position.y - num2 * 1.1f;
				}
				else
				{
					floatY = position.y - num2 * 0.4f;
				}
			}
			else
			{
				float num3 = coll.transform.lossyScale.x * (itemData.scale / GetLocalScale().x);
				float num4 = coll.size.x * num3;
				floatRange = num4 * 0.1f;
				if (itemData.floatType == 1)
				{
					floatY = position.y - num4 * 1.1f;
				}
				else
				{
					floatY = position.y - num4 * 0.4f;
				}
			}
			FreeFall(base.transform.position, new Vector2(position.x, floatY), false);
			floatValue = (float)Math.PI;
			isMuteInWater = isMute;
		}

		protected virtual bool ScriptCheckCollsStart()
		{
			return false;
		}

		protected virtual bool ScriptCheckCollsEnd()
		{
			return false;
		}

		public void SetPlatformEnabled(bool val)
		{
			if (platforms != null)
			{
				for (int i = 0; i < platforms.Count; i++)
				{
					platforms[i].gameObject.SetActive(val);
				}
			}
		}

		public void SetAllCollidersEnabled(bool val)
		{
			SetColliderEnabled(val);
			SetPlatformColliderEnable(val);
			SetChildsColliderEnabled(val);
		}

		public virtual void SetColliderEnabled(bool val)
		{
			if (coll != null)
			{
				coll.enabled = val;
			}
		}

		public void SetPlatformColliderEnable(bool val)
		{
			if (platforms != null)
			{
				for (int i = 0; i < platforms.Count; i++)
				{
					platforms[i].GetComponent<Collider2D>().enabled = val;
				}
			}
		}

		public void SetChildsVisible(bool val)
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				BaseItem baseItem = childItems[i];
				if (baseItem != null)
				{
					baseItem.SetVisible(val);
				}
			}
		}

		public virtual void SetChildsColliderEnabled(bool val)
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				BaseItem baseItem = childItems[i];
				if (baseItem != null)
				{
					baseItem.SetAllCollidersEnabled(val);
				}
			}
		}

		public bool ContainsChild(BaseItem item)
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i] == item)
				{
					return true;
				}
				if (childItems[i].ContainsChild(item))
				{
					return true;
				}
			}
			return false;
		}

		protected virtual void SortCollList(List<ColliderData> list)
		{
			for (int i = 0; i < list.Count - 1; i++)
			{
				for (int num = list.Count - 1; num > i; num--)
				{
					if (list[num] != null && !(list[num].item == null) && list[num - 1] != null && !(list[num - 1].item == null))
					{
						if (CollNeedFront(list[num - 1].item))
						{
							if (CollNeedFront(list[num].item) && list[num - 1].coll.transform.position.z > list[num].coll.transform.position.z)
							{
								ColliderData value = list[num];
								list[num] = list[num - 1];
								list[num - 1] = value;
							}
						}
						else if (CollNeedFront(list[num].item) || list[num - 1].coll.transform.position.z > list[num].coll.transform.position.z)
						{
							ColliderData value2 = list[num];
							list[num] = list[num - 1];
							list[num - 1] = value2;
						}
					}
				}
			}
		}

		protected bool CollNeedFront(BaseItem item)
		{
			if (item != null && item.itemData.collForceFront)
			{
				return true;
			}
			return false;
		}

		private bool PlaceOnPlatform(BaseItem platform, Transform platformTrans, bool onlyCheckPlace, bool onlyCheckDown)
		{
			if (platform != null && platform.CanPlaceItem(this))
			{
				if (onlyCheckPlace)
				{
					return true;
				}
				PlacePointData placePointData = CheckPlatform(base.transform.position, 10, platformTrans, onlyCheckDown, true, CalculatePlaceAngle(platform));
				if (placePointData.result)
				{
					FreeFall(base.transform.position, placePointData.position);
					platform.AttachItem(this, (DepthType)platform.itemData.placeSortType, AttachType.Place, false);
					return true;
				}
			}
			return false;
		}

		public virtual bool CanPlaceItem(BaseItem item)
		{
			if (itemData.canPlaceTypes != null)
			{
				for (int i = 0; i < itemData.canPlaceTypes.Length; i++)
				{
					int num = itemData.canPlaceTypes[i];
					if ((num == 0 && item.itemData.placeType != 0) || (num != 0 && num == item.itemData.placeType) || (num == 1024 && item.itemData.scriptType == 1))
					{
						return true;
					}
				}
			}
			return false;
		}

		public float CalculatePlaceAngle(BaseItem parentItem)
		{
			if (itemData.parentAngleTyes != null)
			{
				for (int i = 0; i < itemData.parentAngleTyes.Length; i++)
				{
					int num = itemData.parentAngleTyes[i];
					for (int j = 0; j < parentItem.itemData.canPlaceTypes.Length; j++)
					{
						if (parentItem.itemData.canPlaceTypes[j] == num)
						{
							return itemData.parentAngles[i];
						}
					}
				}
			}
			return itemData.normalAngle;
		}

		public virtual void PlayDestroyShakeAnim()
		{
		}

		public void PutBackPlatform()
		{
			RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.position, Vector2.zero, 0f, 1024);
			if (!(raycastHit2D.collider != null))
			{
				return;
			}
			BaseItem component = raycastHit2D.collider.transform.parent.parent.parent.GetComponent<BaseItem>();
			if (!(component != null) || !PlaceOnPlatform(component, raycastHit2D.transform, true, true))
			{
				return;
			}
			if (component.itemData.scriptType == 40)
			{
				waterHeight = archiveData.y;
				waterY = archiveData.y;
				CalculateFloatData(base.transform.position, CalculatePlaceAngle(component), true);
				component.AttachItem(this, (DepthType)component.itemData.placeSortType, AttachType.Place, false);
			}
			else
			{
				component.AttachItem(this, (DepthType)component.itemData.placeSortType, AttachType.Place, false);
				if (raycastHit2D.collider is BoxCollider2D)
				{
					CalculatePlacePoint(raycastHit2D.point, (BoxCollider2D)raycastHit2D.collider, true, true, CalculatePlaceAngle(component));
				}
			}
		}

		public void CheckDontPutOtherSceneItem()
		{
			for (int num = childItems.Count - 1; num >= 0; num--)
			{
				BaseItem baseItem = childItems[num];
				if (baseItem.itemData.dontPutOtherScene && baseItem.parentItem != null && typeof(CharacterItem).IsAssignableFrom(baseItem.parentItem.GetType()))
				{
					ReleaseAttachItem(baseItem);
				}
				else
				{
					baseItem.CheckDontPutOtherSceneItem();
				}
			}
		}

		protected PlacePointData CheckPlatform(Vector3 startPoint, int layer, Transform parent = null, bool onlyCheckDown = false, bool calPlacePoint = true, float placeAngle = 0f)
		{
			List<Transform> list = new List<Transform>();
			for (int i = 0; i < checkDirs.Length; i++)
			{
				if (onlyCheckDown && checkDirs[i].y >= 0f)
				{
					continue;
				}
				RaycastHit2D[] array = RaycastAll(checkDirs[i], startPoint, layer);
				for (int j = 0; j < array.Length; j++)
				{
					if (!(array[j].collider != null) || list.Contains(array[j].collider.transform))
					{
						continue;
					}
					list.Add(array[j].collider.transform);
					if (!(parent != null) || !(array[j].collider.transform.parent != parent))
					{
						PlacePointData placePoint = GetPlacePoint(array[j], layer, calPlacePoint, placeAngle);
						if (placePoint.result)
						{
							return placePoint;
						}
					}
				}
			}
			return new PlacePointData(false, Vector2.zero);
		}

		private PlacePointData GetPlacePoint(RaycastHit2D hit, int layer, bool calculatePoint, float placeAngle)
		{
			if (calculatePoint && coll != null)
			{
				Collider2D collider = hit.collider;
				if (collider is BoxCollider2D)
				{
					if (layer != 8)
					{
						return CalculatePlacePoint(hit.point, (BoxCollider2D)collider, true, true, placeAngle);
					}
					if (collider.gameObject.name.EndsWith("_L"))
					{
						return CalculatePlacePoint(hit.point, (BoxCollider2D)collider, true, false, placeAngle);
					}
					if (collider.gameObject.name.EndsWith("_R"))
					{
						return CalculatePlacePoint(hit.point, (BoxCollider2D)collider, false, true, placeAngle);
					}
					if (collider.gameObject.name.EndsWith("_LR"))
					{
						return CalculatePlacePoint(hit.point, (BoxCollider2D)collider, true, true, placeAngle);
					}
				}
			}
			return new PlacePointData(true, hit.point);
		}

		private PlacePointData CalculatePlacePoint(Vector2 point, BoxCollider2D pColl, bool checkLeft, bool checkRight, float placeAngle)
		{
			if (coll == null)
			{
				return new PlacePointData(true, point);
			}
			float num = Mathf.Abs(coll.transform.lossyScale.x * (itemData.scale / GetLocalScale().x));
			float num2 = Mathf.Abs(coll.transform.lossyScale.y * (itemData.scale / GetLocalScale().y));
			float num3 = coll.size.x * num;
			float num4 = Mathf.Abs(pColl.size.x * pColl.transform.lossyScale.x);
			float num5 = pColl.transform.position.x - num4 / 2f + pColl.offset.x * pColl.transform.lossyScale.x;
			float num6 = num5 + num4;
			if (num3 > num4)
			{
				return new PlacePointData(false, point);
			}
			float num7 = coll.size.y * num2;
			float num8;
			float num9;
			if (placeAngle != 0f && num7 <= num4)
			{
				num8 = point.x - num7 / 2f;
				num9 = num8 + num7;
			}
			else
			{
				num8 = point.x - num3 / 2f + coll.offset.x * num + originalModelOffsetX * num;
				num9 = num8 + num3;
				forceStand = true;
			}
			if (checkLeft && num8 < num5)
			{
				return new PlacePointData(true, new Vector2(point.x + num5 - num8, point.y));
			}
			if (checkRight && num9 > num6)
			{
				return new PlacePointData(true, new Vector2(point.x - num9 + num6, point.y));
			}
			return new PlacePointData(true, point);
		}

		private void CalculateModelOffset(bool isLeft)
		{
			if (isLeft)
			{
				targetModelOffsetX = coll.size.x / 2f - coll.offset.x;
				targetModelOffsetY = 0f;
			}
			else
			{
				targetModelOffsetX = (0f - coll.size.x) / 2f - coll.offset.x;
				targetModelOffsetY = 0f;
			}
		}

		public List<BaseItem> GetAllChilds()
		{
			List<BaseItem> list = new List<BaseItem>();
			for (int i = 0; i < childItems.Count; i++)
			{
				list.Add(childItems[i]);
				List<BaseItem> allChilds = childItems[i].GetAllChilds();
				for (int j = 0; j < allChilds.Count; j++)
				{
					list.Add(allChilds[j]);
				}
			}
			return list;
		}

		protected void FreeFall(Vector2 startPoint, Vector2 endPoint, bool rebound = true)
		{
			moveAnimType = MoveAnimType.FreeFall;
			startMoveX = startPoint.x;
			startMoveY = startPoint.y;
			moveEndPoint = endPoint;
			moveTime = 0f;
			isDown = true;
			reboundNum = 0;
			needRebound = rebound;
			SetArchiveDataPosition(endPoint);
			if (startMoveX == moveEndPoint.x && startMoveY == moveEndPoint.y)
			{
				isDown = false;
				accSpeedX = 0f;
				accSpeedY = accSpeed;
				moveYInitV = 3f;
			}
			else
			{
				float num = 0f;
				num = ((startMoveX > moveEndPoint.x) ? (0f - (startMoveX - moveEndPoint.x)) : ((!(startMoveX < moveEndPoint.x)) ? 0f : (moveEndPoint.x - startMoveX)));
				float num2 = 0f;
				num2 = ((startMoveY > moveEndPoint.y) ? (0f - (startMoveY - moveEndPoint.y)) : ((!(startMoveY < moveEndPoint.y)) ? 0f : (moveEndPoint.y - startMoveY)));
				float num3 = Mathf.Sqrt(num * num + num2 * num2);
				accSpeedX = accSpeed * num / num3;
				accSpeedY = accSpeed * num2 / num3;
			}
		}

		private RaycastHit2D[] RaycastAll(Vector2 dir, Vector3 pos, int layer)
		{
			return Physics2D.RaycastAll(pos, dir, 20f, 1 << layer);
		}

		protected virtual void OnMove()
		{
		}

		public virtual void AddCreateItem(BaseItem item)
		{
			if (item != null && !archiveData.createIndexs.Contains(item.archiveData.index))
			{
				archiveData.createIndexs.Add(item.archiveData.index);
				item.archiveData.createParentIndex = archiveData.index;
			}
		}

		public virtual void RemoveCreateItem(BaseItem item)
		{
			if (item != null)
			{
				archiveData.createIndexs.Remove(item.archiveData.index);
				item.archiveData.createParentIndex = 0u;
			}
		}

		public virtual bool AttachItem(BaseItem item, DepthType depthType, AttachType attachType, bool updatePosition)
		{
			if (item == null || item.parentItem != null)
			{
				return false;
			}
			switch (attachType)
			{
			case AttachType.Place:
				item.SetParent(GetPlatformPoint());
				break;
			case AttachType.PlacePoint:
				item.SetParent(GetPlacePoint());
				if (updatePosition)
				{
					if (itemData.type == 3)
					{
						item.SetLocalPosition(0f, -0.68f);
					}
					else
					{
						item.SetLocalPosition(0f, 0f);
					}
				}
				break;
			case AttachType.Sit:
				if (item.itemData.scriptType == 1)
				{
					((CharacterItem)item).ChangeAnimation(CharacterAnimator.AnimName.Sit);
					if (((CharacterItem)item).animator.animName != CharacterAnimator.AnimName.Sit)
					{
						return false;
					}
					if (itemData.sitType == 1 || itemData.sitType == 3)
					{
						item.SetParent(GetSitPoint());
						if (updatePosition)
						{
							item.SetLocalPosition(0f, -0.852f);
						}
					}
					else
					{
						item.SetParent(model);
					}
				}
				else if (itemData.sitType == 1 || itemData.sitType == 3)
				{
					item.SetParent(GetSitPoint());
					if (updatePosition)
					{
						item.SetLocalPosition(0f, 0f);
					}
				}
				else
				{
					item.SetParent(model);
				}
				break;
			case AttachType.LieLeft:
				if (item.itemData.scriptType == 1)
				{
					CharacterItem characterItem = (CharacterItem)item;
					characterItem.ChangeAnimation(CharacterAnimator.AnimName.LieLeft);
					if (characterItem.animator.animName == CharacterAnimator.AnimName.LieLeft)
					{
						item.SetParent(GetLiePoint());
						characterItem.ChangeFaceAnimation(Face.State.Sleep);
						if (updatePosition)
						{
							item.SetLocalPosition(0f, 0f);
						}
						break;
					}
					return false;
				}
				return false;
			case AttachType.LieRight:
				if (item.itemData.scriptType == 1)
				{
					CharacterItem characterItem3 = (CharacterItem)item;
					characterItem3.ChangeAnimation(CharacterAnimator.AnimName.LieRight);
					if (characterItem3.animator.animName == CharacterAnimator.AnimName.LieRight)
					{
						item.SetParent(GetLiePoint());
						characterItem3.ChangeFaceAnimation(Face.State.Sleep);
						if (updatePosition)
						{
							item.SetLocalPosition(0f, 0f);
						}
						break;
					}
					return false;
				}
				return false;
			case AttachType.LieCenter:
				if (item.itemData.scriptType == 1)
				{
					CharacterItem characterItem2 = (CharacterItem)item;
					characterItem2.ChangeAnimation(CharacterAnimator.AnimName.LieCenter);
					if (characterItem2.animator.animName == CharacterAnimator.AnimName.LieCenter)
					{
						item.SetParent(GetLiePoint());
						characterItem2.ChangeFaceAnimation(Face.State.Sleep);
						if (updatePosition)
						{
							item.SetLocalPosition(0f, 0f);
						}
						break;
					}
					return false;
				}
				return false;
			case AttachType.LieLeftPlace:
				if (item.itemData.scriptType == 123)
				{
					((BabyItem)item).ChangeFaceAnimation(Face.State.Sleep);
				}
				item.SetParent(GetPlatformPoint());
				break;
			}
			item.parentItem = this;
			if (!childItems.Contains(item))
			{
				childItems.Add(item);
			}
			if (inWater)
			{
				item.InWater(true, waterHeight);
			}
			item.attachType = attachType;
			if (attachType == AttachType.LeftHandTake || attachType == AttachType.RightHandTake)
			{
				depthSystem.AddChildNode(item.depthSystem, depthType, true);
			}
			else
			{
				depthSystem.AddChildNode(item.depthSystem, depthType);
			}
			SetChildItemLayer(item, archiveData.layer, archiveData.mapId);
			item.OnAttachItemComplete(updatePosition);
			if (archiveData.layer == 9)
			{
				CheckDontPutOtherSceneItem();
			}
			return true;
		}

		protected virtual void SetChildItemLayer(BaseItem item, int layer, int mapId)
		{
			if (item != null)
			{
				item.SetLayer(layer, mapId);
			}
		}

		public virtual void OnAttachItemComplete(bool updatePosition)
		{
		}

		public void ReleaseAllAttachItems()
		{
			for (int num = childItems.Count - 1; num >= 0; num--)
			{
				ReleaseAttachItem(childItems[num]);
			}
		}

		public virtual void ReleaseAttachItem(BaseItem item)
		{
			Singleton<Scene>.Instance.AttachItemToLayer(item, 0);
			item.parentItem = null;
			childItems.Remove(item);
			item.attachType = AttachType.None;
			item.OnReleaseAttachItem(this);
		}

		public virtual void OnReleaseAttachItem(BaseItem oldParent)
		{
		}

		public virtual Transform GetDestroyPoint()
		{
			if (model != null)
			{
				Transform transform = model.Find("DestroyPoint");
				if (transform != null)
				{
					return transform;
				}
				Trace.LogWarning("物件" + itemData.id + " 未配置DestroyPoint");
				return model;
			}
			Trace.LogWarning("物件" + itemData.id + " 未配置DestroyPoint");
			return base.transform;
		}

		public virtual Transform GetSitPoint()
		{
			if (model != null)
			{
				Transform transform = model.Find("SitPoint");
				if (transform != null)
				{
					return transform;
				}
				Trace.LogWarning("物件" + itemData.id + " 未配置SitPoint");
				return model;
			}
			Trace.LogWarning("物件" + itemData.id + " 未配置SitPoint");
			return base.transform;
		}

		public Transform GetPlatform()
		{
			if (platforms != null && platforms.Count > 0)
			{
				return platforms[0];
			}
			return model;
		}

		public virtual AudioPlayer GetAudioPlayer(bool is3DAudio = true)
		{
			if (audioPlayer == null)
			{
				audioPlayer = Singleton<AudioManager>.Instance.CreateAudioPlayer(base.transform, is3DAudio);
			}
			return audioPlayer;
		}

		public virtual Transform GetLiePoint()
		{
			if (model != null)
			{
				Transform transform = model.Find("LiePoint");
				if (transform != null)
				{
					return transform;
				}
				Trace.LogWarning("物件" + itemData.id + " 未配置LiePoint");
				return model;
			}
			Trace.LogWarning("物件" + itemData.id + " 未配置LiePoint");
			return base.transform;
		}

		public Transform GetStackPoint()
		{
			if (model != null)
			{
				Transform transform = model.Find("StackPoint");
				if (transform != null)
				{
					return transform;
				}
				Trace.LogWarning("物件" + itemData.id + " 未配置StackPoint");
				return model;
			}
			Trace.LogWarning("物件" + itemData.id + " 未配置StackPoint");
			return base.transform;
		}

		public float GetBodyHeight()
		{
			if (coll != null)
			{
			}
			return 0f;
		}

		public Transform GetPlatformPoint()
		{
			if (platforms != null && platforms.Count > 0)
			{
				return platforms[0];
			}
			if (model != null)
			{
				return model;
			}
			return base.transform;
		}

		public Transform GetPlacePoint()
		{
			if (model != null)
			{
				Transform transform = model.Find("Platform/Point");
				if (transform != null)
				{
					return transform;
				}
				Trace.LogWarning("物件" + itemData.id + " 未配置PlacePoint");
				return model;
			}
			Trace.LogWarning("物件" + itemData.id + " 未配置PlacePoint");
			return base.transform;
		}

		public static int GenarateDragIndex()
		{
			globalDragIndex++;
			if (globalDragIndex > 100)
			{
				globalDragIndex = 1;
			}
			return globalDragIndex;
		}

		public void SetLocalPosition(float x, float y)
		{
			base.transform.localPosition = new Vector3(x, y, base.transform.localPosition.z);
		}

		public void SetRotation(Vector3 val)
		{
			base.transform.eulerAngles = val;
		}

		public void SetLocalRotation(Vector3 val)
		{
			base.transform.localEulerAngles = val;
		}

		public Quaternion GetRotation()
		{
			return base.transform.rotation;
		}

		public Quaternion GetLocalRotation()
		{
			return base.transform.localRotation;
		}

		public virtual void UpdateFrontDepth()
		{
			if (frontMask != null)
			{
				frontMask.SetLocalZ(0f - depthSystem.frontThickness - 0.0002f);
			}
			if (waterLine != null)
			{
				waterLine.SetZ(base.transform.position.z - depthSystem.frontThickness - 0.00021f);
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i] != null)
				{
					childItems[i].UpdateFrontDepth();
				}
			}
		}

		public void UpdateBackDepth()
		{
			if (backMask != null)
			{
				if (parentItem != null && (attachType == AttachType.PutHead || attachType == AttachType.PutBody))
				{
					backMask.SetZ(parentItem.transform.position.z + parentItem.depthSystem.backThickness + 0.0001f);
				}
				else
				{
					backMask.SetZ(base.transform.position.z + depthSystem.backThickness + 0.00010999999f);
				}
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i] != null)
				{
					childItems[i].UpdateBackDepth();
				}
			}
		}

		public void WalkToLocalPosition(Vector2 position)
		{
			moveEndPoint = position;
			moveAnimType = MoveAnimType.WalkToLocalPoint;
		}

		public void MoveToLocalPosition(Vector2 position)
		{
			moveEndPoint = position;
			moveTime = 0f;
			moveAnimType = MoveAnimType.MoveToLocalPoint;
		}

		public virtual void SetLayer(int layer, int mapId)
		{
			archiveData.layer = layer;
			archiveData.mapId = mapId;
			for (int i = 0; i < childItems.Count; i++)
			{
				childItems[i].SetLayer(layer, mapId);
			}
		}

		private void InitPlatform()
		{
			if (itemData.canPlaceTypes != null)
			{
				platforms = null;
				int childCount = model.childCount;
				for (int i = 0; i < childCount; i++)
				{
					Transform child = model.GetChild(i);
					if (!child.name.StartsWith("Platform"))
					{
						continue;
					}
					child.gameObject.layer = 11;
					if (platforms == null)
					{
						platforms = new List<Transform>();
					}
					platforms.Add(child);
					if (itemData.placeAttachType == 0)
					{
						int childCount2 = child.childCount;
						for (int j = 0; j < childCount2; j++)
						{
							child.GetChild(j).gameObject.layer = 10;
						}
					}
				}
				if (platforms == null)
				{
					Trace.LogError("物件" + itemData.id + "未配置平台检测区域");
				}
			}
			else if (itemData.lieType != 0)
			{
				model.Find("Platform").gameObject.layer = 11;
			}
		}

		public virtual Color32 GetBodyColor()
		{
			if (itemData != null)
			{
				return itemData.bodyColor;
			}
			return new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
		}

		public virtual void StartBurn()
		{
		}

		public virtual void Burn(float time)
		{
		}

		public virtual void OnChildDoThing(BaseItem item, ChildDoThingType type, object parms)
		{
		}

		private void OnDestroy()
		{
			RemoveAudioPlayer();
		}

		protected void RemoveAudioPlayer()
		{
			if (audioPlayer != null)
			{
				Singleton<AudioManager>.Instance.RemoveAudio(audioPlayer);
				audioPlayer = null;
			}
		}

		public void DestroySelf()
		{
			if (parentItem != null)
			{
				parentItem.ReleaseAttachItem(this);
			}
			if (depthSystem != null)
			{
				depthSystem.RemoveFromParent();
			}
			isDrag = false;
			UnityEngine.Object.Destroy(base.gameObject);
		}

		public virtual void PackData(JSONObject obj)
		{
			PackBasicData(obj);
		}

		protected void PackBasicData(JSONObject obj)
		{
			obj["0"] = archiveData.index;
			obj["54"] = archiveData.mapId;
			obj["1"] = archiveData.itemData.id;
			obj["2"] = base.transform.position.x.ToString("F5");
			obj["3"] = base.transform.position.y.ToString("F5");
			if (attachType == AttachType.Place)
			{
				obj["66"] = 1;
				obj["67"] = base.transform.localPosition.x.ToString("F5");
				obj["68"] = base.transform.localPosition.y.ToString("F5");
			}
			obj["4"] = archiveData.layer;
			obj["5"] = archiveData.dirX;
			if (floatValue != 0f)
			{
				obj["49"] = (floatValue % (float)Math.PI).ToString("F2");
			}
			if (floatY != 0f)
			{
				obj["50"] = floatY.ToString("F2");
			}
			if (floatRange != 0f)
			{
				obj["51"] = floatRange.ToString("F2");
			}
			if (waterHeight != 0f)
			{
				obj["52"] = waterHeight.ToString("F4");
			}
			if (waterY != 0f)
			{
				obj["53"] = waterY.ToString("F5");
			}
			if (archiveData.createParentIndex != 0)
			{
				obj["6"] = archiveData.createParentIndex;
			}
			if (archiveData.createIndexs.Count > 0)
			{
				obj["7"] = PackUIntList(archiveData.createIndexs);
			}
			if (forceStand)
			{
				obj["8"] = forceStand;
			}
			if (depthSystem != null)
			{
				if (depthSystem.frontNodes.Count > 0)
				{
					obj["9"] = PackNodeData(depthSystem.frontNodes);
				}
				if (depthSystem.aheadNodes.Count > 0)
				{
					obj["10"] = PackNodeData(depthSystem.aheadNodes);
				}
				if (depthSystem.behindNodes.Count > 0)
				{
					obj["11"] = PackNodeData(depthSystem.behindNodes);
				}
				if (depthSystem.backNodes.Count > 0)
				{
					obj["12"] = PackNodeData(depthSystem.backNodes);
				}
			}
			if (archiveData.mapId == 101 || archiveData.mapId == 102)
			{
				if (parentItem != null && (parentItem.itemData.scriptType == 73 || parentItem.itemData.scriptType == 153))
				{
					obj["57"] = base.transform.localPosition.x.ToString("F5");
					obj["58"] = base.transform.localPosition.y.ToString("F5");
				}
				else
				{
					obj["57"] = archiveData.localX;
					obj["58"] = archiveData.localY;
				}
			}
			if (putParentItemIndex != 0)
			{
				obj["69"] = putParentItemIndex;
				obj["70"] = putParentItemAttachType;
				obj["71"] = putParentItemDepthType;
			}
		}

		protected virtual string PackUIntList(List<uint> list)
		{
			if (list.Count <= 0)
			{
				return string.Empty;
			}
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				text = text + list[i] + ",";
			}
			return text.Substring(0, text.Length - 1);
		}

		protected virtual string PackIntList(List<int> list)
		{
			if (list.Count <= 0)
			{
				return string.Empty;
			}
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				text = text + list[i] + ",";
			}
			return text.Substring(0, text.Length - 1);
		}

		private string PackNodeData(List<DepthSystem> list)
		{
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				string text2 = text;
				text = text2 + list[i].item.archiveData.index + "," + (int)list[i].item.attachType + "|";
			}
			return text.Substring(0, text.Length - 1);
		}

		public static ItemArchiveData UnpackData(JSONObject obj, ItemData itemData)
		{
			ItemArchiveData itemArchiveData = new ItemArchiveData();
			itemArchiveData.itemData = itemData;
			itemArchiveData.index = (uint)(float)obj["0"];
			itemArchiveData.mapId = obj["54"];
			itemArchiveData.x = obj["2"];
			itemArchiveData.y = obj["3"];
			itemArchiveData.resetPlace = obj["66"] == 1;
			itemArchiveData.placeX = obj["67"];
			itemArchiveData.placeY = obj["68"];
			itemArchiveData.layer = (byte)(int)obj["4"];
			itemArchiveData.dirX = obj["5"];
			itemArchiveData.createParentIndex = (uint)(float)obj["6"];
			itemArchiveData.floatValue = obj["49"];
			itemArchiveData.floatY = obj["50"];
			itemArchiveData.floatRange = obj["51"];
			itemArchiveData.waterY = obj["53"];
			itemArchiveData.waterHeight = obj["52"];
			itemArchiveData.state = obj["33"];
			string text = obj["7"];
			if (!string.IsNullOrEmpty(text))
			{
				string[] array = text.Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					itemArchiveData.createIndexs.Add(uint.Parse(array[i]));
				}
			}
			itemArchiveData.forceStand = obj["8"];
			itemArchiveData.frontNodes = UnpackNodeData(obj["9"]);
			itemArchiveData.aheadNodes = UnpackNodeData(obj["10"]);
			itemArchiveData.behindNodes = UnpackNodeData(obj["11"]);
			itemArchiveData.backNodes = UnpackNodeData(obj["12"]);
			itemArchiveData.localX = obj["57"];
			itemArchiveData.localY = obj["58"];
			itemArchiveData.putParentItemIndex = (uint)(float)obj["69"];
			itemArchiveData.putParentItemAttachType = obj["70"];
			itemArchiveData.putParentItemDepthType = obj["71"];
			if (itemData.scriptType == 1)
			{
				itemArchiveData.intParam1 = obj["59"];
				itemArchiveData.headId = obj["13"];
				itemArchiveData.hairId = obj["14"];
				itemArchiveData.bodyId = obj["15"];
				itemArchiveData.topsId = obj["16"];
				itemArchiveData.topsIconId = obj["17"];
				itemArchiveData.pantsId = obj["18"];
				itemArchiveData.shoesId = obj["19"];
				itemArchiveData.browId = obj["20"];
				itemArchiveData.eyeId = obj["21"];
				itemArchiveData.noseId = obj["22"];
				itemArchiveData.mouthId = obj["23"];
				itemArchiveData.featureId = obj["55"];
				itemArchiveData.hairColor = new Color32((byte)(int)obj["24"], (byte)(int)obj["25"], (byte)(int)obj["26"], byte.MaxValue);
				itemArchiveData.bodyColor = new Color32((byte)(int)obj["27"], (byte)(int)obj["28"], (byte)(int)obj["29"], byte.MaxValue);
				itemArchiveData.color = new Color32((byte)(int)obj["30"], (byte)(int)obj["31"], (byte)(int)obj["32"], byte.MaxValue);
				itemArchiveData.mapX = obj["64"];
				itemArchiveData.mapY = obj["65"];
			}
			else if (itemData.scriptType == 123)
			{
				itemArchiveData.intParam1 = obj["59"];
				itemArchiveData.headId = obj["13"];
				itemArchiveData.topsId = obj["16"];
				itemArchiveData.bodyId = obj["15"];
				itemArchiveData.browId = obj["20"];
				itemArchiveData.eyeId = obj["21"];
				itemArchiveData.noseId = obj["22"];
				itemArchiveData.mouthId = obj["23"];
				itemArchiveData.featureId = obj["55"];
				itemArchiveData.bodyColor = new Color32((byte)(int)obj["27"], (byte)(int)obj["28"], (byte)(int)obj["29"], byte.MaxValue);
				itemArchiveData.color = new Color32((byte)(int)obj["30"], (byte)(int)obj["31"], (byte)(int)obj["32"], byte.MaxValue);
			}
			else if (itemData.scriptType == 2)
			{
				itemArchiveData.pixels = obj["61"];
				itemArchiveData.color = new Color32((byte)(int)obj["30"], (byte)(int)obj["31"], (byte)(int)obj["32"], byte.MaxValue);
			}
			else if (itemData.scriptType == 3)
			{
				itemArchiveData.color = new Color32((byte)(int)obj["30"], (byte)(int)obj["31"], (byte)(int)obj["32"], byte.MaxValue);
			}
			else if (itemData.scriptType == 8)
			{
				itemArchiveData.modelX = obj["34"];
			}
			else if (itemData.scriptType == 17)
			{
				itemArchiveData.intParam1 = obj["59"];
			}
			else if (itemData.scriptType == 14)
			{
				itemArchiveData.topsIconId = obj["17"];
			}
			else if (itemData.scriptType == 20 || itemData.scriptType == 107)
			{
				itemArchiveData.intParam1 = obj["59"];
				itemArchiveData.intParam2 = obj["60"];
			}
			else if (itemData.scriptType == 21)
			{
				itemArchiveData.intParam1 = obj["59"];
			}
			else if (itemData.scriptType == 22 || itemData.scriptType == 71 || itemData.scriptType == 72 || itemData.scriptType == 74 || itemData.scriptType == 100 || itemData.scriptType == 126)
			{
				itemArchiveData.modelX = obj["34"];
				itemArchiveData.modelY = obj["39"];
			}
			else if (itemData.scriptType == 24)
			{
				itemArchiveData.intParam1 = obj["59"];
				itemArchiveData.intParam2 = obj["60"];
				itemArchiveData.bodyColor = new Color32((byte)(int)obj["27"], (byte)(int)obj["28"], (byte)(int)obj["29"], byte.MaxValue);
				itemArchiveData.color = new Color32((byte)(int)obj["30"], (byte)(int)obj["31"], (byte)(int)obj["32"], byte.MaxValue);
			}
			else if (itemData.scriptType == 30)
			{
				itemArchiveData.bodyColor = new Color32((byte)(int)obj["27"], (byte)(int)obj["28"], (byte)(int)obj["29"], byte.MaxValue);
			}
			else if (itemData.scriptType == 33 || itemData.scriptType == 97 || itemData.scriptType == 132)
			{
				itemArchiveData.intList = UnpackIntList(obj["48"]);
			}
			else if (itemData.scriptType == 67)
			{
				itemArchiveData.browId = obj["20"];
				itemArchiveData.eyeId = obj["21"];
				itemArchiveData.noseId = obj["22"];
				itemArchiveData.mouthId = obj["23"];
				itemArchiveData.featureId = obj["55"];
			}
			else if (itemData.scriptType == 93 || itemData.scriptType == 116 || itemData.scriptType == 144 || itemData.scriptType == 160 || itemData.scriptType == 167)
			{
				itemArchiveData.floatParam1 = obj["62"];
			}
			else if (itemData.scriptType == 36)
			{
				itemArchiveData.floatParam1 = obj["62"];
				itemArchiveData.bodyColor = new Color32((byte)(int)obj["27"], (byte)(int)obj["28"], (byte)(int)obj["29"], byte.MaxValue);
			}
			else if (itemData.scriptType == 108)
			{
				itemArchiveData.floatParam1 = obj["62"];
				itemArchiveData.floatParam2 = obj["63"];
			}
			return itemArchiveData;
		}

		protected static List<int> UnpackIntList(string data)
		{
			if (string.IsNullOrEmpty(data))
			{
				return null;
			}
			string[] array = data.Split(',');
			List<int> list = new List<int>();
			for (int i = 0; i < array.Length; i++)
			{
				list.Add(int.Parse(array[i]));
			}
			return list;
		}

		protected static List<ChildNodeData> UnpackNodeData(string nodeData)
		{
			if (string.IsNullOrEmpty(nodeData))
			{
				return null;
			}
			string[] array = nodeData.Split('|');
			List<ChildNodeData> list = new List<ChildNodeData>();
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(',');
				ChildNodeData item = new ChildNodeData(uint.Parse(array2[0]), int.Parse(array2[1]));
				list.Add(item);
			}
			return list;
		}

		public static ItemArchiveData CreateBasicData(ItemData itemData, int layer, float x, float y, bool needNodes)
		{
			ItemArchiveData itemArchiveData = new ItemArchiveData();
			itemArchiveData.index = 0u;
			itemArchiveData.x = x;
			itemArchiveData.y = y;
			itemArchiveData.layer = layer;
			itemArchiveData.dirX = 1;
			itemArchiveData.itemData = itemData;
			itemArchiveData.forceStand = itemData.forceStand;
			itemArchiveData.state = itemData.state;
			if (itemData.floatType == 2)
			{
				itemArchiveData.waterHeight = y;
				itemArchiveData.floatY = y - itemData.floatWaterHeight;
				itemArchiveData.waterY = y;
			}
			if (itemData.scriptType == 1)
			{
				itemArchiveData.headId = itemData.headId;
				itemArchiveData.hairId = itemData.hairId;
				itemArchiveData.bodyId = itemData.bodyId;
				itemArchiveData.topsId = itemData.topsId;
				itemArchiveData.topsIconId = itemData.topsIconId;
				itemArchiveData.pantsId = itemData.pantsId;
				itemArchiveData.shoesId = itemData.shoesId;
				itemArchiveData.browId = itemData.browId;
				itemArchiveData.eyeId = itemData.eyeId;
				itemArchiveData.noseId = itemData.noseId;
				itemArchiveData.mouthId = itemData.mouthId;
				itemArchiveData.featureId = itemData.featureId;
				itemArchiveData.hairColor = itemData.hairColor;
				itemArchiveData.bodyColor = itemData.bodyColor;
				itemArchiveData.mapX = x;
				itemArchiveData.mapY = y;
			}
			else if (itemData.scriptType == 123)
			{
				itemArchiveData.headId = itemData.headId;
				itemArchiveData.bodyId = itemData.bodyId;
				itemArchiveData.topsId = itemData.topsId;
				itemArchiveData.browId = itemData.browId;
				itemArchiveData.eyeId = itemData.eyeId;
				itemArchiveData.noseId = itemData.noseId;
				itemArchiveData.mouthId = itemData.mouthId;
				itemArchiveData.featureId = itemData.featureId;
				itemArchiveData.bodyColor = itemData.bodyColor;
			}
			else if (itemData.scriptType == 2)
			{
				itemArchiveData.pixels = null;
				itemArchiveData.color = itemData.color;
			}
			else if (itemData.scriptType == 3)
			{
				itemArchiveData.color = itemData.color;
			}
			else if (itemData.scriptType == 14)
			{
				itemArchiveData.topsIconId = itemData.topsIconId;
			}
			else if (itemData.scriptType == 20)
			{
				itemArchiveData.intParam1 = 0;
				itemArchiveData.intParam2 = 1;
			}
			else if (itemData.scriptType == 24)
			{
				itemArchiveData.bodyColor = itemData.bodyColor;
				itemArchiveData.color = itemData.color;
				itemArchiveData.intParam1 = itemData.tyreId;
				itemArchiveData.intParam2 = itemData.tyreId;
			}
			else if (itemData.scriptType == 67)
			{
				itemArchiveData.browId = 4;
				itemArchiveData.eyeId = 2;
				itemArchiveData.noseId = 3;
				itemArchiveData.mouthId = 8;
				itemArchiveData.featureId = 6;
				itemArchiveData.state = 1;
			}
			else if (itemData.scriptType == 135)
			{
				itemArchiveData.bodyColor = itemData.bodyColor;
				itemArchiveData.floatParam1 = 0.5f;
			}
			return itemArchiveData;
		}
	}
}
